<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="建议办理"></uni-navbar></view>

		<view class="u-line"></view>
		<u-row class="link-box" gutter="0" align="top">
			<u-col span="3" v-if="$sysMenus('motion_add')">
				<navigator hover-class="none" class="link-item" url="/pagesB/proposal/add">
					<image src="/static/img/icon_28.png" mode="aspectFill"></image>
					提交建议
				</navigator>
			</u-col>
			<u-col span="3" v-if="$sysMenus('motion_clue')">
				<navigator hover-class="none" class="link-item" url="/pagesA/clue/list?type=motion">
					<image src="/static/img/icon_29.png" mode="aspectFill"></image>
					线索征集
				</navigator>
			</u-col>
			<u-col span="3">
				<navigator hover-class="none" class="link-item" url="/pagesB/proposal/list">
					<image src="/static/img/icon_30.png" mode="aspectFill"></image>
					所有建议
				</navigator>
			</u-col>
			<u-col span="3" v-if="$sysMenus('motion_add')">
				<navigator hover-class="none" class="link-item" url="/pagesB/proposal/spare_list?status=0">
					<image src="/static/img/icon_31.png" mode="aspectFill"></image>
					草稿箱
				</navigator>
			</u-col>
			<u-col span="3" v-if="$sysMenus('lm_motion')">
				<navigator hover-class="none" class="link-item" url="/pagesB/proposal/list_lianming">
					<image src="/static/img/icon_32.png" mode="aspectFill"></image>
					联名建议
				</navigator>
			</u-col>
			<u-col span="3" v-if="$sysMenus('proposals_statistics')">
				<navigator hover-class="none" class="link-item" url="/pagesB/proposal/statistics">
					<image src="/static/img/icon_33.png" mode="aspectFill"></image>
					统计分析
				</navigator>
			</u-col>
		</u-row>

		<!-- <view class="pro-inner">
			<view class="h2-inner"><view class="h2-title">总体概况</view></view>
			<view>所有建议</view>
			<view class="pro-item"><u-line-progress :active-color="['#3DBBFF', '#3396FB']" :percent="100" :text="numAll"></u-line-progress></view>
			<view>立案</view>
			<view class="pro-item"><u-line-progress :active-color="['#67FFDB', '#77DDC5']" :percent="parseInt((num101 / numAll) * 100)" :text="num101"></u-line-progress></view>
			<view>不立案</view>
			<view class="pro-item"><u-line-progress :active-color="['#FF7783', '#E80824']" :percent="parseInt((num25 / numAll) * 100)" :text="num25"></u-line-progress></view>
			<view>转来信</view>
			<view class="pro-item"><u-line-progress :active-color="['#FAD961', '#F76B1C']" :percent="parseInt((num21 / numAll) * 100)" :text="num21"></u-line-progress></view>
		</view> -->

		<view class="plus-inner">
			<view class="h2-inner">
				<view class="h2-title">总体概况</view>
				<view>截止{{ $parseTime(new Date(), '{y}.{m}.{d} {h}:{i}') }}</view>
			</view>
			<view class="plus-box">
				<view class="plus-item bg90" @click="listTo('/pagesB/proposal/list')">
					<view class="title">{{ numAll }}</view>
					<view>所有建议</view>
				</view>
				<view class="plus-item bg91" @click="listTo('/pagesB/proposal/list?status=3,4,5,6,7,8&ex=1')">
					<view class="title">{{ num101 }}</view>
					<view>接收办理</view>
				</view>
				<view class="plus-item bg92" @click="listTo('/pagesB/proposal/list?status=23&ex=2')">
					<view class="title">{{ num23 }}</view>
					<view>不予接收</view>
				</view>
				<!-- <view class="plus-item bg93" @click="listTo('/pagesB/proposal/list?status=21')">
					<view class="title">{{ num21 }}</view>
					<view>转来信</view>
				</view> -->
			</view>
		</view>

		<view class="pro-row-plus">
			<view class="pro-col" @click="listTo('/pagesB/proposal/list?status=5')">
				<text style="color: #3396fb">{{ num5 }}</text>
				办理中
			</view>
			<view class="pro-col" @click="listTo('/pagesB/proposal/list?status=6')">
				<text style="color: #00b854">{{ num6 }}</text>
				待测评
			</view>
			<view class="pro-col" @click="listTo('/pagesB/proposal/list?status=8')">
				<text style="color: #d0021b">{{ num8 }}</text>
				已办结
			</view>
			<!-- <view class="pro-col" @click="listTo('/pagesB/proposal/list?status=21')">
				<text style="color: #F5A623;">{{ num21 }}</text>
				转来信
			</view> -->
		</view>

		<view class="list-box">
			<view class="filter-inner">
				<view class="filter-btn" :class="filterType == 0 ? 'active' : ''" @click="type(0)">
					<image src="/static/img/icon_11.png" mode="widthFix"></image>
					<image src="/static/img/icon_11_f.png" mode="widthFix"></image>
					我的建议
				</view>
				<view class="filter-btn" :class="filterType == 1 ? 'active' : ''" @click="type(1)">
					<image src="/static/img/icon_10.png" mode="widthFix"></image>
					<image src="/static/img/icon_10_f.png" mode="widthFix"></image>
					公开建议
				</view>
			</view>

			<view class="list-info_02" v-for="(item, index) of proposalList" :key="item.id" @click="navTo(item)">
				<view class="left">
					<view class="info-title">{{ item.title }}</view>
					<view class="info-btm">
						<view class="name clamp">{{ item.kindName }}</view>
						<text class="line"></text>
						<view class="time">{{ item.createTime }}</view>
					</view>
				</view>
				<view class="right" :class="[index % 2 == 0 ? 'bg1' : 'bg2']">建议</view>
			</view>
			<u-loadmore :status="loading" />
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			numAll: 0,
			num5: 0,
			num6: 0,
			num8: 0,
			num21: 0,
			num23: 0,
			num25: 0,
			num101: 0,
			filterType: 0,
			keyword: '',
			proposalList: [],

			motion: {
				ciId: '',
				jieId: '',
				kind: '',
				nodeStatus: '',
				isOpen: '',
				title: '',
				type: ''
			},
			loading: 'loadmore'
		};
	},
	onLoad() {
		this.loadLogin();
		this.loadAll();
		this.loadData();
	},
	onPullDownRefresh() {
		this.loadAll();
		this.loadData('refresh');
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.sysUser) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;
				this.pageNum = 1;
				this.pageSize = 10;
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			if (this.loading == 'loading') {
				return false;
			}
			if (type == 'add') {
				if (this.loading == 'nomore') {
					return false;
				}
				this.loading = 'loading';
			} else {
				this.loading = 'loading';
			}
			if (type != 'add') {
				this.pageNum = 1;
			}
			if (this.filterType == 0) {
				this.motion.isOpen = '';
			} else {
				this.motion.isOpen = '3';
			}

			let data = {
				pageNum: this.pageNum,
				pageSize: this.pageSize,
				clientCode: this.clientCode,
				motion: this.motion
			};
			if (this.filterType == 0) {
				data.currentUserId = this.userId;
				this.$request('/motion/myList', data, {
					load: true
				}).then((res) => {
					let count = 0;
					if (type != 'add') {
						uni.stopPullDownRefresh();
						this.proposalList = [];
					}
					this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
					this.pageNum = this.pageNum + 1;
					// this.proposalList = this.proposalList.concat(res.data.records);
					res.data.records.forEach((item) => {
						this.proposalList.push({
							id: item.id,
							title: item.title,
							kindName: item.kindName,
							createTime: item.createTime
						});
					});
					this.loaded = true;
					if (this.proposalList.length <= 0) {
						this.loading = 'nodata';
					}
				});
			} else {
				this.$request('/motion/list', data, {
					load: true
				}).then((res) => {
					let count = 0;
					if (type != 'add') {
						uni.stopPullDownRefresh();
						this.proposalList = [];
					}
					this.loading = this.pageNum < Math.ceil(res.data.total / this.pageSize) ? 'loadmore' : 'nomore';
					this.pageNum = this.pageNum + 1;
					this.proposalList = this.proposalList.concat(res.data.records);
					this.loaded = true;
					if (this.proposalList.length <= 0) {
						this.loading = 'nodata';
					}
				});
			}
		},
		loadAll() {
			let data = {
				currentUserId: this.userId,
				clientCode: this.clientCode
			};
			this.$request('/motion/statistics/indexCount', data).then((res) => {
				this.numAll = res.data.count_all;
				this.num5 = res.data.count_5;
				this.num6 = res.data.count_6;
				this.num8 = res.data.count_8;
				this.num21 = res.data.count_21 || 0;
				this.num23 = res.data.count_23 || 0;
				this.num25 = res.data.count_25 || 0;
				this.num101 = res.data.countLian || 0;
			});
		},
		search(e) {
			this.keyword = e;
			this.loadData('refresh');
		},
		type(e) {
			this.filterType = e;
			this.loadData('refresh');
		},
		listTo(url) {
			uni.navigateTo({
				url: url
			});
		},
		navTo(item) {
			uni.navigateTo({
				url: '/pagesB/proposal/detail?id=' + item.id
			});
		}
	}
};
</script>

<style lang="scss">
.list-box {
	// margin-bottom: 30rpx;
	padding: 30rpx 30rpx 0;
	// border-radius: 30rpx;
	background-color: #fff;
}
</style>
